<!-- filepath: e:\Product\my-vue3-project\src\views\ForgotPassword.vue -->
<template>
  <div class="forgot-container">
    <el-card class="forgot-card">
      <h2>找回密码</h2>
      <el-form
        :model="form"
        :rules="rules"
        ref="forgotFormRef"
        label-width="80px"
      >
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" autocomplete="off" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">发送重置邮件</el-button>
          <el-button type="text" @click="goToLogin">返回登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";

const router = useRouter();
const forgotFormRef = ref();
const form = ref({
  email: "",
});

const rules = {
  email: [
    { required: true, message: "请输入邮箱", trigger: "blur" },
    { type: "email", message: "邮箱格式不正确", trigger: "blur" },
  ],
};

const onSubmit = () => {
  forgotFormRef.value.validate((valid: boolean) => {
    if (valid) {
      // 这里可以调用接口
      ElMessage.success("重置邮件已发送");
      router.push("/login");
    }
  });
};

const goToLogin = () => {
  router.push("/login");
};
</script>

<style scoped>
.forgot-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.forgot-card {
  width: 350px;
}
</style>
